"""fix venue type column

Revision ID: 20251031_fix_type
Revises: 20251031_add_venue_fields
Create Date: 2025-10-31 23:30:00.000000

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect


# revision identifiers, used by Alembic.
revision = '20251031_fix_type'
down_revision = '20251031_add_venue_fields'
branch_labels = None
depends_on = None


def upgrade():
    """修改 venues.type 列的类型和长度"""
    bind = op.get_bind()
    inspector = inspect(bind)
    
    # 检查 type 列是否存在
    columns = {col['name']: col for col in inspector.get_columns('venues')}
    
    if 'type' in columns:
        print(f"当前 type 列定义: {columns['type']}")
        
        # 修改 type 列为 VARCHAR(100)
        print("修改 type 列为 VARCHAR(100)...")
        op.alter_column('venues', 'type',
                       existing_type=sa.String(),
                       type_=sa.String(100),
                       existing_nullable=True)
        print("✅ type 列修改完成")
    else:
        print("⚠️ type 列不存在")


def downgrade():
    """回退操作"""
    # 不需要回退，保持原样
    pass

